﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class EventImage : MonoBehaviour, IPointerEnterHandler,IPointerExitHandler,IPointerClickHandler
{
    public UnityEvent enterEvent;
    public UnityEvent clickEvent;
    public bool highLightAni = true;
    public bool scaleAni = false;
    public bool canCtrl = true;

    public void OnPointerEnter(PointerEventData eventData)
    {
        if (!canCtrl) return;
        Slected();
        enterEvent.Invoke();
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        if (!canCtrl) return;
        NoSlected();
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        if (!canCtrl) return;
        clickEvent.Invoke();
    }
    private void Slected()
    {
        GetComponent<Image>().color = Color.green;
        if (scaleAni)
        {
            transform.localScale += Vector3.one*0.3f;
        }
    }
    private void NoSlected()
    {
        GetComponent<Image>().color = Color.white;
        if (scaleAni)
        {
            transform.localScale -= Vector3.one * 0.3f;
        }
    }

    public void SetCanCtrl(bool b)
    {
        canCtrl = b;
        if (b)
        {
            GetComponent<Image>().color = Color.white;
        }
        else
        {
            GetComponent<Image>().color = Color.gray;
        }
    }


}
